package com.bt.lms.service.impl;

import com.bt.lms.bo.Page;
import com.bt.lms.constant.BOConstant;
import com.bt.lms.entity.CourseInfo;
import com.bt.lms.entity.TeachingPlanBasicInfo;
import com.bt.lms.bo.TeachingPlanCondition;
import com.bt.lms.dao.servise.TeachingPlanDao;
import com.bt.lms.dao.servise.impl.TeachingPlanDaoImpl;
import com.bt.lms.service.TeachingPlanService;


import java.util.List;

/**
 * 教学计划接口实现类
 * @author 李舒淇
 */
public class TeachingPlanServiceImpl implements TeachingPlanService {


    @Override
    public boolean add(TeachingPlanBasicInfo teachingPlanBasicInfo) throws Exception {
        //1.需要系统维护的属性（不是用户输入的属性）
        teachingPlanBasicInfo.setStatus(BOConstant.TEACHING_PLAN_BASIC_INFO_STATUS_DRAFT);



        String sql = "insert into teaching_plan(code,name,Learning_Center,apply_Level,length_Of_Schooling_text,length_Of_Schooling,number_of_repairable_times,status,current_Term) values(?,?,?,?,?,?,?,?,?)";
        TeachingPlanDao teachingPlanServiceDao = new TeachingPlanDaoImpl();
        teachingPlanServiceDao.insert(sql,teachingPlanBasicInfo);


        return false;
    }

    @Override
    public boolean relevancyCourse(Long id, List<CourseInfo> courses) {

        return false;
    }

    @Override
    public TeachingPlanBasicInfo details(Long id) throws Exception {

        //sql语句
        String sql = "select * from teaching_plan where id =?";
        TeachingPlanBasicInfo teachingPlanBasicInfo = new TeachingPlanBasicInfo();
        TeachingPlanDao teachingPlanDao = new TeachingPlanDaoImpl();
        teachingPlanDao.select(sql,teachingPlanBasicInfo,id);

        return teachingPlanBasicInfo;
    }


    @Override
    public boolean accomplish(Long id) throws Exception {
        //sql语句
        String sql = "UPDATE teaching_plan set confirm_completion = ? WHERE id =?";
        TeachingPlanDao teachingPlanDao = new TeachingPlanDaoImpl();
        teachingPlanDao.accomplish(sql,id);

        return false;
    }


    @Override
    public boolean enable(Long id) throws Exception {
        //sql语句
        String sql = "UPDATE teaching_plan set status = ? WHERE id =?";
        TeachingPlanDao teachingPlanDao = new TeachingPlanDaoImpl();
        teachingPlanDao.enable(sql,id);

        return false;
    }


    @Override
    public boolean edit(Long id, TeachingPlanBasicInfo teachingPlanBasicInfo) throws Exception {
        //状态
        teachingPlanBasicInfo.setStatus(1);
        //sql语句
        String sql = "update teaching_plan set code =?,name=?,learning_Center=?,apply_Level=?,length_Of_Schooling_Text=?,length_Of_Schooling=?,number_Of_Repairable_Times=?,status=?,rel_Course_Quantity=?,current_Term=? WHERE id=?";
        TeachingPlanDao teachingPlanDao = new TeachingPlanDaoImpl();
        teachingPlanDao.edit(sql,teachingPlanBasicInfo,id);


        return false;
    }


    @Override
    public boolean delete(Long id) throws Exception {

        //sql语句
        String sql = "UPDATE teaching_plan set is_deleted = ? WHERE id =?";
        TeachingPlanDao teachingPlanDao = new TeachingPlanDaoImpl();
        teachingPlanDao.delete(sql,id);

        return false;
    }

    @Override
    public Page<TeachingPlanBasicInfo> query(Page<TeachingPlanCondition> page, Page<TeachingPlanBasicInfo> teachingPage) {

        //sql语句

        String sql = "SELECT * FROM teaching_plan LIMIT ?,?";
        TeachingPlanDao teachingPlanDao = new TeachingPlanDaoImpl();
        Page<TeachingPlanBasicInfo> query = null;
        try {
            query = teachingPlanDao.query(sql, page, teachingPage);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return query;
    }
}
